import Recommender.FeatureRepresentation as Feature
import Recommender.RecommenderTagBased as RecommenderTagBased
import time
from datetime import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
import sys
sys.path.append('C:/Project/Python3')
sys.path.append('D:/Project/Python3')

# --- Load Config File---
from Recommender.Config import *
config = Config()
database = config.DataBase()


# ---定期重构词库---
def Rebuild_VocabularyFile():
    Feature.Build_UserDefinedVocabularyFile(database, "/")


# --- 定期重算IDF（每月？）---
def Caculate_IDF():
    # ---以最近10000篇为基础计算IDF---
    Feature.Calc_IDF_Batch(database, {"limit": 10000, "orderby": {"publish_time": -1}})


# --- 批量重打所有标签（不删除旧标签）---
# --- 在标签库发生巨大改变时使用---
def AddTag_on_Article():
    # ---Add Tags to Article---
    # method: PreDefined 只要遇到标签库的词就视为标签
    # method: TopTFTDF 保留TFIDF最大的5个词为标签
    filter = {"limit": 10000, "orderby": {"publish_time": -1}}
    Feature.AddTag_on_Article_Batch(database, filter, "TopTFIDF")



print("Recommender Scheduler Manager Started")
schedudler = BlockingScheduler()

now = datetime.now()
start_date = datetime(now.year, now.month, now.day, now.hour, 0, 0)

#
# schedudler.add_job(SecondTask, 'interval', seconds=5)
# schedudler.add_job(MinuteTask, 'interval', minutes=1, start_date=start_date)
# schedudler.add_job(HourTask, 'interval', hours=1, start_date=start_date)


# cron定时调度
schedudler.add_job(Caculate_IDF, 'cron', month='1-12', day=1, hour=0, minute=0, second=0)
